package com.frame.demo.ui.activity;

import android.view.View;
import android.widget.EditText;

import com.frame.demo.R;
import com.frame.demo.app.TitleBaseBindPresenterActivity;
import com.frame.demo.injector.component.ActivityComponent;
import com.frame.demo.rest.model.bean.LoginBean;
import com.frame.demo.ui.presenter.LoginPresenter;
import com.frame.demo.ui.view.LoginView;
import com.frame.demo.util.EncryptionUtil;
import com.frame.demo.util.PromptUtil;
import com.support.android.designlibdemo.DrawerMainActivity;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2015/12/29.
 */
public class LoginActivity extends TitleBaseBindPresenterActivity<LoginPresenter> implements LoginView {
    @Inject
    LoginPresenter mLoginPresenter;
    @BindView(R.id.et_username)
    EditText mEtUsername;
    @BindView(R.id.et_password)
    EditText mEtPassword;

    @Override
    public LoginPresenter getPresenter() {
        return mLoginPresenter;
    }

    @Override
    public int inflateContentView() {
        return R.layout.activity_login_layout;
    }

    @Override
    public void loginSuccess(LoginBean loginBean) {
        PromptUtil.showNormalToast("success");
        DrawerMainActivity.launch(this);
    }



    @OnClick({R.id.btn_login})
    public void dealOnclick(View pView) {
        switch (pView.getId()) {
            case R.id.btn_login:
                    mLoginPresenter.login(mEtUsername.getText().toString(),
                            EncryptionUtil.encryptPassword(mEtPassword.getText().toString()));
                break;
        }
    }

    @Override
    public void initActivity(View view) {
        super.initActivity(view);
        ButterKnife.bind(this, view);
        getToolbar().setNavigationIcon(null);
        showContent();
    }

    @Override
    public void inject(ActivityComponent pActivityComponent) {
        pActivityComponent.inject(this);
    }

}
